
HOSTURL = "http://..."

function SendPostRequest(sendJsonData, recvType="json") {
    $.ajax ({
        type: "POST",
        url: '/',
        data: JSON.stringify(sendJsonData),
        dataType: recvType,
        success: function (respMsg, Status) {
            window.location.href = '/webroot/index.html'
        },
        error: function (respMsg, Status) {
            console.log(respMsg);
            console.log(Status);
        },
    });
}

function SendGetRequest(httpUrl) {
    $.ajax({
        type: "GET",
        url: httpUrl,
        success: function(data, textStatus) {
            window.location.href = httpUrl
        },
        error: function (data, textStatus) {
            console.log(data);
        },
    });
}

$(document).ready(function () {
    $("#xjh-login").click(function () {
        var postData = {
            "msgType": "CLIENT_LOGIN",
            "username": $("#username").val(),
            "password": $("#password").val()
        }
        if (postData["username"] != "" && postData["password"] != "") {
            $("#login-marked-words").text('Logging in ...')
            SendPostRequest(postData)
        } else {
            $("#login-marked-words").text('ERROR: username or password is NULL !');
        }
    });
});